package com.science.slam.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class PasswdUtils {
    public static String SHA1(String passwd) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            byte[] inputBytes = passwd.getBytes();
            byte[] hashBytes = md.digest(inputBytes);

            StringBuilder hexString = new StringBuilder();
            for (byte b : hashBytes) {
                String hex = Integer.toHexString(0xff & b);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }

            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            System.out.println(e.getMessage());
            return null;
        }
    }
}
